﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SharpRedisDesktopManager.Core.Services;
using SharpRedisDesktopManager.Core.ViewModels;
using SharpRedisDesktopManager.UserControls;

namespace SharpRedisDesktopManager
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow
    {
        private static RedisManagement redis = new RedisManagement();
        private MainWindowViewModel viewModel;

        public MainWindow()
        {
            InitializeComponent();
        }

        protected override void OnContentRendered(EventArgs e)
        {
            base.OnContentRendered(e);


            InitConnections();
            DataContext = viewModel;

            NonClientAreaContent = new NonClientAreaContent();
        }

        private void InitConnections()
        {
            viewModel = new MainWindowViewModel();
            redis.AddConnection();
            redis.AddConnection();
            redis.AddConnection();
            viewModel.ConnectionInfos = new System.ComponentModel.BindingList<Core.Models.RedisConnectionInfo>(redis.All());
        }

        private void BtnNewConnection_Click(object sender, RoutedEventArgs e)
        {
            redis.AddConnection();
            viewModel.ConnectionInfos = new System.ComponentModel.BindingList<Core.Models.RedisConnectionInfo>(redis.All());
            ListRedisConnections.ItemsSource = viewModel.ConnectionInfos;
        }
    }
}
